home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 15107 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.6 KB

  1. Path: global.gc.net!sourcebbs!david.mohorn
  2. From: david.mohorn@sourcebbs.com (DAVID MOHORN)
  3. Newsgroups: comp.lang.c
  4. Subject: COLLEGE PROFESSORS! # 1/2
  5. Message-ID: <8BEC555.02C70031C3.uuout@sourcebbs.com>
  6. Date: Tue, 16 Apr 96 22:45:00 -0500
  7. Distribution: world
  8. Organization: SelectiveSourceBBS VirginiaBeach  (804)471 6776
  9. Reply-To: david.mohorn@sourcebbs.com (DAVID MOHORN)
  10. X-Newsreader: PCBoard Version 15.22
  11. X-Mailer: PCBoard/UUOUT Version 1.20
  12.  
  13. I can't stand it!  I cannot believe the way my VisualBASIC instructor at
  14. college is teaching his students to program.  He and I had it out during
  15. class tonight over this programming construct, which I will demonstrate
  16. in pseudocode.
  17.  
  18. This routine is called only to validate a string that is passed and
  19. return a condition, either GOOD or BAD:
  20.  
  21. EXAMPLE 1:
  22. *** start of validation routine ***
  23. declare StatusSwitch string
  24.  
  25. define StatusSwitch string as "GOOD"
  26.  
  27. if( condition1 ) then
  28. else
  29.    display error message
  30.    set StatusSwitch="BAD"
  31.  
  32. if( condition2 and StatusSwitch="GOOD" ) then
  33. else
  34.    display error message
  35.    set StatusSwitch="BAD"
  36.  
  37. if( condition3 and StatusSwitch="GOOD" ) then
  38. else
  39.    display error message
  40.    set StatusSwitch="BAD"
  41.  
  42. if( condition4 and StatusSwitch="GOOD" ) then
  43. else
  44.    display error message
  45.    set StatusSwitch="BAD"
  46.  
  47. return StatusSwitch
  48. *** end of validation routine ***
  49.  
  50. versus the simple, yet elegant approach of:
  51.  
  52. EXAMPLE 2:
  53. *** start of validation routine ***
  54. declare StatusSwitch string
  55.  
  56. define StatusSwitch string as "GOOD"
  57.  
  58. if( condition1 ) then
  59. else
  60.    display error message
  61.    return StatusSwitch
  62.  
  63. if( condition2 ) then
  64. else
  65.    display error message
  66.    return StatusSwitch
  67.  
  68. if( condition3 ) then
  69. else
  70.    display error message
  71.    return StatusSwitch
  72.  
  73. if( condition4 ) then
  74. else
  75.    display error message
  76.    return StatusSwitch
  77.  
  78. return StatusSwitch
  79. *** end of validation routine ***
  80.  
  81. or even a better approach:
  82.  
  83. EXAMPLE 3:
  84. *** start of validation routine ***
  85. declare StatusSwitch string
  86.  
  87. define StatusSwitch string as "GOOD"
  88.  
  89. if( condition1 ) then
  90. else
  91.    display error message
  92.    return StatusSwitch
  93. else
  94. if( condition2 ) then else
  95.    display error message
  96.    return StatusSwitch
  97. else
  98. if( condition3 ) then
  99. else
  100.    display error message
  101.    return StatusSwitch
  102. else
  103. if( condition4 ) then
  104. else
  105.    display error message
  106.    return StatusSwitch
  107.  
  108. (Continued to next message)
  109. ---
  110.  * QMPro 1.53 * Programming is 10% inspiration and 90% debugging.
  111.  
  112.  
  113. ---
  114. This message originated from:  ----------        Selective Source BBS
  115.                                     -------    Virginia Beach, Virginia
  116.                                          -----      (804) 471 6776
  117.